import { login, logout, getInfo } from "@/api/login";
import { getToken, setToken, removeToken } from "@/utils/auth";
import { getGoodsDetail } from '@/api/goods'

const goodsDetail = {
  state: {
    userAddress:[],
    goodsDetail: {},
    goodsInfo:{
      goodsImg: [

      ],
      title: '苹果8/7手机壳iPhone7 Plus保护壳全包防摔磨砂硬外壳',
      tags: ['满69-20元', '关注产品★送钢化膜', 'BIT配次日达'],
      discount: ['满148减10', '满218减20', '满288减30'],
      promotion: ['跨店满减', '多买优惠'],
      remarksNum: 6000,
      setMeal: [
        [
          {
            img: '',
            intro: '4.7英寸-深邃蓝',
            price: 28.0
          },
          {
            img: '',
            intro: '4.7英寸-星空黑',
            price: 29.0
          },
          {
            img: '',
            intro: '5.5英寸-香槟金',
            price: 28.5
          }
        ],
        [
          {
            img: '',
            intro: '5.5英寸-玫瑰金',
            price: 32.0
          },
          {
            img: '',
            intro: '5.5英寸-深邃蓝',
            price: 32.0
          },
          {
            img: '',
            intro: '5.5英寸-星空黑',
            price: 35.0
          }
        ],
        [
          {
            img: '',
            intro: '4.7英寸-香槟金',
            price: 26.0
          },
          {
            img: '',
            intro: '4.7英寸-玫瑰金',
            price: 25.0
          },
          {
            img: '',
            intro: '4.7英寸-中国红',
            price: 28.0
          }
        ]
      ],
      hot: [
        {
          img: '',
          price: 28.0,
          sale: 165076
        },
        {
          img: '',
          price: 36.0,
          sale: 135078
        },
        {
          img: '',
          price: 38.0,
          sale: 105073
        },
        {
          img: '',
          price: 39.0,
          sale: 95079
        },
        {
          img: '',
          price: 25.0,
          sale: 5077
        },
        {
          img: '',
          price: 20.0,
          sale: 3077
        }
      ],
      goodsDetail: [

      ],
      param: [
        {
          title: '商品名称',
          content: 'iPhone 7手机壳'
        },
        {
          title: '商品编号',
          content: '10435663237'
        },
        {
          title: '店铺',
          content: 'Gavin Shop'
        },
        {
          title: '商品毛重',
          content: '100.00g'
        },
        {
          title: '商品产地',
          content: '中国大陆'
        },
        {
          title: '机型',
          content: 'iPhone 7'
        },
        {
          title: '材质',
          content: 'PC/塑料'
        },
        {
          title: '款式',
          content: '软壳'
        },
        {
          title: '适用人群',
          content: '通用'
        }
      ],
      remarks: {
        goodAnalyse: 90,
        remarksTags: [ '颜色可人', '实惠优选', '严丝合缝', '极致轻薄', '质量没话说', '比定做还合适', '完美品质', '正品行货', '包装有档次', '不容易发热', '已经买第二个', '是全覆盖' ],
        remarksNumDetail: [ 2000, 3000, 900, 1 ],
        detail: [
          {
            username: 'p****1',
            values: 3,
            content: '颜色很好看，质量也不错！，还送了个指环，想不到哦！',
            goods: '4.7英寸-深邃蓝',
            create_at: '2018-05-15 09:20'
          },
          {
            username: '13****1',
            values: 5,
            content: '手感没的说，是硬壳，后背带有磨砂手感。很不错，很喜欢，还加送了钢化膜，支架环，物超所值，准备再买一个。很满意。物流很快。很愉快的一次购物！',
            goods: '5.5英寸-玫瑰金',
            create_at: '2018-05-13 15:23'
          },
          {
            username: '3****z',
            values: 4.5,
            content: '相当轻薄，店家还送了一大堆配件，*元非常值得！',
            goods: '4.7英寸-玫瑰金',
            create_at: '2018-05-05 12:25'
          },
          {
            username: 'gd****c',
            values: 3.5,
            content: '就是我想要的手机壳，壳子很薄，手感不错，就像没装手机壳一样，想要裸机手感的赶快下手了。',
            goods: '4.7英寸-中国红',
            create_at: '2018-04-06 16:23'
          },
          {
            username: 'r****b',
            values: 4.5,
            content: '壳子还不错，送的膜也可以，不过还是感觉膜小了那么一点，屏幕没法完全覆盖。对了，壳子稍微有点硬，可能会伤漆，所以不要频繁取壳就好。',
            goods: '4.7英寸-中国红',
            create_at: '2018-03-15 19:24'
          },
          {
            username: 'd****e',
            values: 5,
            content: '磨砂的，相当漂亮，尺寸非常合适！精工细作！',
            goods: '5.5英寸-星空黑',
            create_at: '2018-03-10 10:13'
          }
        ]
      }
    }
  },
  
  mutations: {
    SET_GOODS_DETAISL: (state, goodsDetail) => {
      state.goodsDetail = goodsDetail;
    },
    SET_GOODS_INFO: (state, goodsInfo) => {
      state.goodsInfo = goodsInfo;
    },
    SET_USER_ADDRESS: (state, userAddress) => {
      state.userAddress = userAddress;
    },
  },

  actions: {
    loadAddress({ commit }) {
      return new Promise((resolve, reject) => {
        const address = [
          {
            addressId: "123456",
            name: "Gavin",
            province: "广东省",
            city: "广州市",
            area: "天河区",
            address: "燕岭路633号",
            phone: "152****0609",
            postalcode: "510000",
          },
          {
            addressId: "123458",
            name: "Kevin",
            province: "上海市",
            city: "上海市",
            area: "浦东新区",
            address: "沙新镇",
            phone: "158****0888",
            postalcode: "200120",
          },
        ];
        commit("SET_USER_ADDRESS", address);
      });
    },

    loadGoodsDetail({ commit }, goods) {
      const uid = goods.id;
      return new Promise((resolve, reject) => {
        getGoodsDetail({id:uid}).then((res) => {
            res.data.addNumber = 1
            commit("SET_GOODS_DETAISL", res.data);
            resolve();
          })
          .catch((error) => {
            reject(error);
          });
      });
    },
    // 前端 登出
    FedLogOut({ commit }) {
      return new Promise((resolve) => {
        commit("SET_TOKEN", "");
        removeToken();
        resolve();
      });
    },
  },
};

export default goodsDetail;
